import functools

class Solution:
    # @param {integer[]} nums
    # @return {string}
    def largestNumber(self, nums):
        nums = [str(num) for num in nums]
        def cmp(a, b):
            length = min(len(a),len(b))
            for ca, cb in zip(a[:length],b[:length]):
                if ca!=cb: return -1 if ca<cb else 1
            if len(a)==len(b): return 0
            elif len(a)>len(b):
                a = a[length:]
            elif len(a)<len(b):
                b = b[length:]
            return cmp(a,b)
        nums.sort(key=functools.cmp_to_key(cmp),reverse=True)
        return str(int(''.join(nums)))

print(Solution().largestNumber([3,30,34,5,9]))